library(dplyr)
library(DT)
library(plotly)
library(summarytools)
Z strony pobralismy dane do pliku csv usuwamy również tu nie potrzbne kolumny
tweets <- read.csv("tweets-engagement-metrics.csv")
kolumny_do_usuniecia <- c("UserID", "LocationID","StateCode", "TweetID")
tweets <- tweets[, -which(names(tweets) %in% kolumny_do_usuniecia)]
summary(tweets)
## X Gender City State
## Min. : 0 Length:102062 Length:102062 Length:102062
## 1st Qu.: 25515 Class :character Class :character Class :character
## Median : 51031 Mode :character Mode :character Mode :character
## Mean : 51031
## 3rd Qu.: 76546
## Max. :102061
## Country Hour Day Weekday
## Length:102062 Min. : 0.00 Min. : 1.0 Length:102062
## Class :character 1st Qu.: 7.00 1st Qu.: 9.0 Class :character
## Mode :character Median :11.00 Median :16.0 Mode :character
## Mean :11.42 Mean :15.9
## 3rd Qu.:16.00 3rd Qu.:23.0
## Max. :23.00 Max. :31.0
## IsReshare Reach RetweetCount Likes
## Length:102062 Min. : 0 Min. : 0.000 Min. : 0.0000
## Class :character 1st Qu.: 152 1st Qu.: 0.000 1st Qu.: 0.0000
## Mode :character Median : 454 Median : 0.000 Median : 0.0000
## Mean : 8426 Mean : 7.986 Mean : 0.1497
## 3rd Qu.: 1519 3rd Qu.: 3.000 3rd Qu.: 0.0000
## Max. :10342452 Max. :26127.000 Max. :133.0000
## Klout Sentiment Lang text
## Min. : 0.00 Min. :-6.0000 Length:102062 Length:102062
## 1st Qu.:32.00 1st Qu.: 0.0000 Class :character Class :character
## Median :43.00 Median : 0.0000 Mode :character Mode :character
## Mean :40.41 Mean : 0.3808
## 3rd Qu.:49.00 3rd Qu.: 0.6000
## Max. :99.00 Max. : 7.3333
# Wybierz kraj
selected_country <- unique(tweets$Country)
selected_country <- selected_country[1]
# Wybierz płeć
selected_gender <- unique(tweets$Gender)
selected_gender <- selected_gender[1]
# Filtruj dane według wybranego kraju i płci
filtered_data <- tweets %>%
filter(Country == selected_country, Gender == selected_gender) %>%
arrange(Hour)
# Stwórz wykres słupkowy dla wizualizacji częstości
freq_data <- table(filtered_data$Hour)
plot_ly(x = names(freq_data), y = freq_data, type = 'bar') %>%
layout(title = 'Ilość tweetów w zależności od pory dnia',
xaxis = list(title = 'Wartości', categoryorder = 'array', categoryarray = 1),
yaxis = list(title = 'Częstość'))
# Wygeneruj przykładowe 10 tweetów
head(filtered_data, 10)
## X Gender City State Country Hour Day Weekday IsReshare Reach
## 1 0 Unknown Elbasan Elbasan Albania 7 12 Friday True 339
## RetweetCount Likes Klout Sentiment Lang
## 1 127 0 44 0 en
## text
## 1 "RT @AdrianRusso82: Our Innovation Lab is officially open! Click below to learn more! https://www.linkedin.com/pulse/new-innovation-lab-open-business-adrian-russo-msis-mcp?utm_source&utm_medium&utm_campaign #Tech #JavaScript #AWS http"
# Pobierz wybraną kolumnę z danych
selected_sentiment <- filtered_data$Sentiment
# Oblicz wybrane statystyki za pomocą dplyr
sentiment_stats <- data.frame(
Statystyka = c(
"Średnia", "Mediana", "Odchylenie standardowe", "Minimum", "Maksimum", "n"
),
Wartość = c(
mean(selected_sentiment),
median(selected_sentiment),
round(sd(selected_sentiment), 2), # Zaokrąglanie SD do 2 miejsc po przecinku
min(selected_sentiment),
max(selected_sentiment),
length(selected_sentiment)
)
)
# Wyświetl statystyki w formie tabeli DataTable
datatable(sentiment_stats, options = list(dom = 't'), rownames = FALSE)
# Pobierz wybraną kolumnę z danych
selected_retweets <- filtered_data$RetweetCount
# Oblicz wybrane statystyki za pomocą dplyr
retweets_stats <- data.frame(
Statystyka = c(
"Średnia", "Mediana", "Odchylenie standardowe", "Minimum", "Maksimum", "n"
),
Wartość = c(
mean(selected_retweets),
median(selected_retweets),
round(sd(selected_retweets), 2), # Zaokrąglanie SD do 2 miejsc po przecinku
min(selected_retweets),
max(selected_retweets),
length(selected_retweets)
)
)
# Wyświetl statystyki w formie tabeli DataTable
datatable(retweets_stats, options = list(dom = 't'), rownames = FALSE)
# Analiza wariancji dla wybranej zmiennej
selected_variable <- "Sentiment"
anova_results <- aov(
as.formula(paste0(selected_variable, " ~ Gender")),
data = tweets
)
summary(anova_results)
## Df Sum Sq Mean Sq F value Pr(>F)
## Gender 3 146 48.65 44.48 <2e-16 ***
## Residuals 102058 111628 1.09
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Stwórz histogram dla zmiennej Sentiment
hist(selected_sentiment, main = "Histogram Sentymentu", xlab = "Sentyment", col = "lightblue", border = "black")
# Stwórz histogram dla zmiennej RetweetCount
hist(selected_retweets, main = "Histogram Retweetów", xlab = "Retweety", col = "lightgreen", border = "black")